package com.project.service;

import com.project.bean.UserBean;
import com.project.dao.IUserDao;
import com.project.server.Request;
import com.project.server.Response;
import com.project.uitl.DaoFactory;
import com.project.uitl.WebServlet;

import java.util.List;
@WebServlet("findAll")
public class FindAllService  implements Servlet {
    /**
     * 用户持久主键
     */
    private IUserDao dao =(IUserDao) DaoFactory.getDao("IUserDao");

    public void service(Request request, Response response) {
        List<UserBean> list = dao.findAll();
        String str = "<table border='1' cellspacing='0'  width='80%' style='margin:auto' >";
        str += "<thead><tr><th>用户名</th><th>密码</th><th>生日</th><th>操作</th></tr></thead>";
        str += "<tbody>";
        for (UserBean user : list) {
            str += "<tr><td>" + user.getName() + "</td>" +
                    "<td>" + user.getPwd() + "</td>" +
                    "<td>" + user.getBirthday() + "</td>" +
                    "<td><a href='del?id=" + user.getId() + "'>删除 </a>" +
                    "<a href='findById?id=" + user.getId() + "'>修改 </a></td></tr>";
        }
        str += "</table></table>";
        response.sendMessage(str);
    }


}
